#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<math.h>
const int d = 1000001;
int not_isprime[d];
int isprime[d];
int main() {
    int n;
    
    int index = 1;
    not_isprime[2] = 0;
    for (int i = 2; i <= d; i++) {
        if (not_isprime[i] == 0) {
            isprime[index++] = i;
            for (int j = 1;  j < index && j <= d / i; j++) {
                not_isprime[i * isprime[j]] = 1;
                if (i % isprime[j] == 0) break;
            }
        }
    }
    while (~scanf("%d", &n)) {
        int f = 1;
        for (int i = 1; i < index; i++) {
            if (isprime[i] == n)
            {
                printf("%d\n", i);
                f = 0;
                break;
            }
        }
        if (f)
            printf("0\n");
    }
    return 0;
}